import { useEffect } from "react"
import { useAppDispatch, useAppSelector } from "./useRedux"
import { getProjects, setSelectedProject } from "@/redux/projects/projectsSLice"

const useFetchProjects = () => {
  const dispatch = useAppDispatch()
  const { selectedProjectId, projects, loading, status } = useAppSelector((state) => state.projects)

  useEffect(() => {
    if (!selectedProjectId) {
      dispatch(getProjects())
    }
  }, [dispatch, selectedProjectId])

  const handleProjectSelect = (projectId: string) => {
    dispatch(setSelectedProject(projectId));
  };

  // const removeProject = () => {

  // }

  return { handleProjectSelect, projects, loading, status, selectedProjectId }
}
export default useFetchProjects